package com.cake.liulanxiangzhu.controller;

import com.cake.liulanxiangzhu.pojo.dto.AdminAlbumDTO;
import com.cake.liulanxiangzhu.pojo.dto.AdminAlbumInsertDTO;
import com.cake.liulanxiangzhu.pojo.vo.AdminAlbumVO;
import com.cake.liulanxiangzhu.service.AdminAlbumService;
import com.cake.liulanxiangzhu.web.JsonPage;
import com.cake.liulanxiangzhu.web.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@Validated
@RequestMapping("/album")
public class AdminAlbumController {
    @Autowired
    private AdminAlbumService albumService;

    @PostMapping("/addNew")
    public JsonResult<Void> addNew(@Valid AdminAlbumInsertDTO adminAlbumInsertDTO) {
        albumService.addNew(adminAlbumInsertDTO);
        return JsonResult.ok();
    }

    @PostMapping("/deleteById")
    public JsonResult<Void> deleteById(Integer id) {
        albumService.deleteById(id);
        return JsonResult.ok();
    }


    @PostMapping("/update")
    public JsonResult<Void> updateById(AdminAlbumDTO adminAlbumDTO) {
        albumService.updateById(adminAlbumDTO);
        return JsonResult.ok();
    }

    @GetMapping("/selectALL")
    public JsonResult<JsonPage<AdminAlbumVO>> selectALL(Integer page, Integer pageSize){
        JsonPage<AdminAlbumVO> adminAlbumVOJsonPage = albumService.selectAllAlbums(page, pageSize);
        return JsonResult.ok(adminAlbumVOJsonPage);
    }

    @GetMapping("/selectById")
    public JsonResult<AdminAlbumVO> selectById(Integer id){
        AdminAlbumVO adminAlbumVO = albumService.setByAlbumId(id);
        return JsonResult.ok(adminAlbumVO);
    }

    @GetMapping("/selectALLAlbum")
    public JsonResult<List<AdminAlbumVO>> selectALLAlbum( ){
        List<AdminAlbumVO> vos = albumService.listAll();
        return JsonResult.ok(vos);
    }

}
